package com.example.tagsdemo.handler;

import com.example.tagsdemo.dto.GeneratorDTO;
import com.example.tagsdemo.entity.DBTable;
import com.example.tagsdemo.entity.DBTableColumns;
import com.example.tagsdemo.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public abstract class AbstractHandler {

    abstract public ResultVO handle(GeneratorDTO dto);

    protected DBTable getTables(List<DBTable> tableList, String tableName) {
        for(DBTable table : tableList) {
            if (table.getName().equalsIgnoreCase(tableName)) {
                return table;
            }
        }
        return null;
    }

    protected  String getIdType(List<DBTableColumns> columnsList) {
        for(DBTableColumns c: columnsList) {
            if (StringUtils.equalsIgnoreCase("id",c.getColumnName())) {
                return c.getTypeName();
            }
        }
        return null;
    }
}
